#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
from datetime import timedelta


class DefaultConfig:
    """默认配置类"""
    
    # 基本配置
    SECRET_KEY = os.environ.get("SECRET_KEY", "dev-key-please-change-in-production")
    DEBUG = False
    TESTING = False
    
    # 数据库配置
    DB_HOST = os.environ.get("DB_HOST", "45.205.31.46")
    DB_PORT = int(os.environ.get("DB_PORT", 3306))
    DB_USER = os.environ.get("DB_USER", "root")
    DB_PASSWORD = os.environ.get("DB_PASSWORD", "jpyvLZIX6549!")
    DB_NAME = os.environ.get("DB_NAME", "test_tools")
    DB_CHARSET = os.environ.get("DB_CHARSET", "utf8mb4")
    
    # 数据库连接URI
    SQLALCHEMY_DATABASE_URI = os.environ.get(
        "DATABASE_URL", 
        f"mysql+pymysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}?charset={DB_CHARSET}"
    )
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_ENGINE_OPTIONS = {
        "pool_recycle": 280,  # 连接回收时间，小于数据库超时时间
        "pool_timeout": 20,   # 连接池获取连接的超时时间
        "pool_size": 10,      # 连接池大小
        "max_overflow": 5     # 最大溢出连接数
    }
    
    # CORS配置
    CORS_HEADERS = 'Content-Type'
    
    # JWT配置
    JWT_SECRET_KEY = os.environ.get("JWT_SECRET_KEY", SECRET_KEY)
    JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=1)
    JWT_REFRESH_TOKEN_EXPIRES = timedelta(days=30)
    
    # 日志配置
    LOG_LEVEL = "INFO"
    LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
    
    # 上传文件配置
    MAX_CONTENT_LENGTH = 16 * 1024 * 1024  # 16MB
    UPLOAD_FOLDER = os.path.join("instance", "uploads")
    
    # API配置
    API_TITLE = "企业级Flask API"
    API_VERSION = "1.0"
    API_DESCRIPTION = "企业级Flask API服务" 